/*
 * FSplashScreen.java
 *
 * Created on 06 February 2005, 17:02
 */

package org.foment.joliage3.newt;

import javax.swing.plaf.SliderUI;

/**
 *
 * @author  civan
 */
public class SplashScreen extends javax.swing.JDialog {
  private javax.swing.ImageIcon mainImage = null;
  private javax.swing.ImageIcon progresBarInactive = null;
  private javax.swing.ImageIcon progresBarActive = null;
  private java.awt.image.BufferedImage buffer = null;
  private int padding = 0;
  private java.awt.Color bgColor = java.awt.Color.WHITE;
  
  private java.util.Vector<String> states = new java.util.Vector();
  private int currState = 0;
  
  /** Creates new form FSplashScreen */
  public SplashScreen(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    //setD
  }
  
  public void addState(String state) {
    states.add(state);  
    updateBuffer();
  }
  
  public void proceedToNextState() {
    if (currState < states.size() - 1) {
      currState++;
      //this.repaint(100);
      updateBuffer();
      paint(this.getGraphics());
      //updateBuffer();
      //this.invalidate();
      //this.repaint(0);
    }  
  }
  
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        pack();
    }// </editor-fold>//GEN-END:initComponents

  public void updateBuffer() {
    java.awt.Graphics g = buffer.getGraphics();
    g.setColor(bgColor);
    //g.
    g.fillRect(0, 0, buffer.getWidth(), buffer.getHeight());
    //g.clearRect(0, 0, buffer.getWidth(), buffer.getHeight());
    g.setColor(java.awt.Color.BLACK);
    g.setFont(g.getFont().deriveFont(java.awt.Font.BOLD));
    
    mainImage.paintIcon(this, g, padding, padding);
    progresBarInactive.paintIcon(this, g, padding, 2 * padding + mainImage.getIconHeight());
    
    if ((states.size() > 1) && (states.size() - 1 != currState)) {
      java.awt.Graphics g2 = g.create(padding, 2 * padding + mainImage.getIconHeight(), (progresBarActive.getIconWidth() / (states.size() - 1)) * currState, progresBarActive.getIconHeight());
      progresBarActive.paintIcon(this, g2, 0, 0);
    } else {
      progresBarActive.paintIcon(this, g, padding, 2 * padding + mainImage.getIconHeight());
    }
    String caption = states.get(currState);
    g.drawString(caption, (buffer.getWidth() - g.getFontMetrics().stringWidth(caption)) / 2, buffer.getHeight() - 5);
  }
  
  public void initState() {
    if (mainImage != null && progresBarActive != null && progresBarInactive != null) {
      int height = mainImage.getIconHeight() + progresBarActive.getIconHeight() + 3 * padding;
      int width = mainImage.getIconWidth() + 2 * padding;
      java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
      setBounds((screenSize.width - width) / 2, (screenSize.height - height)/2, width, height);
      buffer = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_RGB);
      this.repaint();
    }
  }  
  /**
   * @param args the command line arguments
   */
  
  public void paint(java.awt.Graphics g) {
    //super.paint(g);
    g.drawImage(buffer, 0, 0, null);
  }

  public javax.swing.Icon getMainImage() {
    return mainImage;
  }

  public void setMainImage(javax.swing.ImageIcon mainImage) {
    this.mainImage = mainImage;
    initState();
  }

  public javax.swing.ImageIcon getProgresBarInactive() {
    return progresBarInactive;
  }

  public void setProgresBarInactive(javax.swing.ImageIcon progresBarInactive) {
    this.progresBarInactive = progresBarInactive;
    initState();
  }

  public javax.swing.ImageIcon getProgresBarActive() {
    return progresBarActive;
  }

  public void setProgresBarActive(javax.swing.ImageIcon progresBarActive) {
    this.progresBarActive = progresBarActive;
    initState();
  }

  public int getPadding() {
    return padding;
  }

  public void setPadding(int padding) {
    this.padding = padding;
    initState();
  }

  public java.awt.Color getBgColor() {
    return bgColor;
  }

  public void setBgColor(java.awt.Color bgColor) {
    this.bgColor = bgColor;
    if (bgColor != null) setBackground(bgColor);
    initState();
  }
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
  
}
